package com.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.entity.Attribute;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AttributeMapper extends BaseMapper<Attribute> {

    @Select("SELECT attr_id,attr_name,cat_id,attr_sel,attr_write,attr_vals FROM sp_attribute WHERE cat_id=#{id} AND attr_sel=#{sel};")
    List<Attribute> getList(Integer id, String sel);

    @Insert("INSERT INTO sp_attribute (cat_id,attr_name,attr_sel,attr_vals) VALUES(#{cat_id},#{attr_name},#{attr_sel},#{attr_vals})")
    int add(Attribute attribute);

    @Select("SELECT attr_id,attr_name,cat_id,attr_sel,attr_write,attr_vals  FROM sp_attribute WHERE cat_id=#{cat_id} AND attr_name =#{attr_name} and attr_sel=#{attr_sel}")
    Attribute selectByAtt(Attribute attribute);

    @Update("UPDATE sp_attribute SET attr_name =#{attr_name},attr_sel=#{attr_sel} WHERE cat_id=#{cat_id} AND attr_id=#{attr_id}")
    int updateAtt(Attribute attribute);

    @Insert("INSERT INTO sp_attribute (cat_id,attr_name,attr_sel) VALUES(#{cat_id},#{attr_name},#{attr_sel})")
    int adds(Attribute attribute);
}
